Skip to content
This repository was archived by the owner on Oct 13, 2021. It is now read-only.

otel-trace-py implementation #3

Merged
merged 11 commits into from
Nov 7, 2019
Merged

otel-trace-py implementation #3

merged 11 commits into from
Nov 7, 2019

Conversation

mauriciovasquezbernal
Copy link
Contributor

This PR includes a series of commits that implemented otel-trace-py.

  • remove non needed parts
  • project renaming
  • add new features
    -- compatibility with opentelemetry exporters and api to configure them
    -- w3c and b3 propagators support

remove everything related to dogstatsd and disable metrics, in future
then can be enable again and connected to the otel metrics api
That logic is not needed to send traces to opentelemetry
The following is the list of references that had been renamed.

DATADOG_                     ->    OPENTELEMETRY_
Datadog                      ->    OpenTelemetry
DD_                          ->    OTEL_
_dd                          ->    _otel
ddtrace                      ->    oteltrace
_datadog_                    ->    _opentelemetry_
datadog_                     ->    opentelemetry_
datadog/foo                  ->    opentelemetry/foo
datadog.tracer               ->    opentelemetry.tracer
datadog                      ->    opentelemetry
dd_                          ->    otel_
aotel                        ->    add
DDLogger                     ->    OtelLogger
dd\.trace                    ->    otel\.trace
dd\.span                     ->    otel\.span
dd-trace-py                  ->    otel-trace-py
dd-trace-py                  ->    otel-trace-py
https://github.com/DataDog   ->    https://github.com/opentelemetry
https://github.com/DataDog   ->    https://github.com/opentelemetry
'http://www.datadog.com/'    ->    'http://opentelemetry.io/'
python 2.7 is not supported by OpenTelemetry
The APIOtel class uses an OpenTelemetry SDK exporter to send traces.  The
exporter to be used must be passed at creation time.

This commit also modifies the writer class to receive the API object to use
as a paremeter, it also extends tracer.configure() to allow to set the api
object.

...
from oteltrace import patch_all
patch_all()

import oteltrace
from opentelemetry.ext.jaeger import JaegerSpanExporter
from oteltrace.api_otel_exporter import APIOtel

jaeger_exporter = JaegerSpanExporter(
    service_name='my-helloworld-service',
)

oteltrace.tracer.configure(
  api=APIOtel(exporter=jaeger_exporter)
)

application starts here...
...

Users of oteltrace-run can configure it by using some env variables:
- OTEL_EXPORTER_MODULE specifies the python module where the exporter is
  implemented
- OTEL_EXPORTER_FACTORY defines a function to be called to get an instance of
  the exporter.

The options passed to OTEL_EXPORTER_FACTORY are defined also using env
variables, all variables starting with OTEL_EXPORTER_OPTIONS_ will be
passed as kwargs.
This commit implements new http propagators in other to be compatible with
OpenTelemetry instrumented apps:
- w3c: default context propagator in opentelemetry
- b3: another choice
tracer.configure() was extended to accept a new parameter, "http_propagator",
this is a factory function that will be used to get new instances of the
propagator to be used.

The following is an example of how to set b3 as the propagator:

...
from oteltrace.propagation.b3 import B3HTTPPropagator

oteltrace.tracer.configure(
    http_propagator=B3HTTPPropagator
)
...

Users of oteltrace-run can choose the propagator to be used by setting the
OTEL_TRACER_PROPAGATOR env variable to one of the  current supported values:
w3c, b3 and datadog.
This commit add two basic examples
the first one shows how to use oteltrace-run and how to configure the
opentelemetry and http propagator by using env variables.
The second example uses the oteltrace API to perform the exporter and the
propagator.
test integration uses ddog agent & api, that does not exist anymore
@codeboten
Copy link
Contributor

Looks good. Is there a test for w3c context propagation and I just missed it?

@mauriciovasquezbernal
Copy link
Contributor Author

There is this https://github.com/w3c/trace-context/tree/master/test.

It's used in opentelemetry-python: open-telemetry/opentelemetry-python#228.

The idea is to follow a similar approach here and use that for testing the w3c.

@codeboten codeboten merged commit ee7633d into master Nov 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants